package cn.xy.commons.enums;

import cn.xy.commons.validator.VerifiedEnum;
import lombok.Getter;

/**
 * 状态枚举
 *
 *  @author xy
 */
@Getter
public enum DisableStatus implements VerifiedEnum {

    /**
     * 正常
     */
    NORMAL(1, "正常"),

    /**
     * 停用
     */
    DISABLE(2, "停用");

    /**
     * int值
     */
    private final int value;

    /**
     * 对应文本
     */
    private final String name;

    DisableStatus(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public static boolean isNormal(int value) {
        return value == NORMAL.value;
    }

    public static boolean isDisable(int value) {
        return !DisableStatus.isNormal(value);
    }

    /**
     * 获取相反值
     *
     * @param status status
     * @return 相反值
     */
    public static int negate(int status) {
        return DISABLE.getValue() == status ? NORMAL.getValue() : DISABLE.getValue();
    }

    /**
     * 通过value获取name
     *
     * @param value value
     * @return name
     */
    public static String getNameByValue(int value) {
        for (DisableStatus status : DisableStatus.values()) {
            if (value == status.getValue()) {
                return status.getName();
            }
        }
        return DISABLE.getName();
    }

    @Override
    public Object getVerifiedValue() {
        return this.value;
    }
}
